import 'package:flutter/material.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/config/app_language.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/pages/game/game_detail/models/model_game_round.dart';
import 'package:flutter_09_game/utils/extensions/num_ext.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

/// 游戏结果动画组件
class GameResultAnimationWidget extends StatelessWidget {
  final ModelGameRoundHistory result;
  final Animation<double> slideAnimation;
  final Animation<double> fadeAnimation;

  const GameResultAnimationWidget({
    super.key,
    required this.result,
    required this.slideAnimation,
    required this.fadeAnimation,
  });

  @override
  Widget build(BuildContext context) {
    final bool isWin = result.isWin ?? false;
    final String iconAsset = isWin ? Assets.gameWinTag : Assets.gameLoseTag;

    return AnimatedBuilder(
      animation: Listenable.merge([slideAnimation, fadeAnimation]),
      builder: (context, child) {
        return Positioned(
          top: slideAnimation.value.w + 50.w,
          left: 0,
          right: 0,
          child: Opacity(
            opacity: fadeAnimation.value,
            child: Container(
              height: 32.w,
              width: double.infinity,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: isWin
                        ? AppColor.gameResultWinBg
                        : AppColor.gameResultLoseBg,
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight),
              ),
              // padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
              // decoration: BoxDecoration(
              //   color: AppColor.navBgColor.withOpacity(0.95),
              //   borderRadius: BorderRadius.circular(8.w),
              //   // boxShadow: [
              //   //   BoxShadow(
              //   //     color: AppColor.black.withOpacity(0.2),
              //   //     blurRadius: 8.w,
              //   //     offset: Offset(0, 2.w),
              //   //   ),
              //   // ],
              // ),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  AutoImage(
                    iconAsset,
                    width: 24.w,
                    height: 24.w,
                  ),
                  12.horizontalSpace,
                  Text(
                    isWin
                        ? LocaleKeys.congratulationsWin.tr
                        : LocaleKeys.sorryTryAgain.tr,
                    style: TextStyle(
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w900,
                        color: Colors.white,
                        fontFamily: 'AR'),
                  ),
                  4.horizontalSpace,
                  Text(
                    "${isWin ? '+' : '-'}${(isWin ? result.winAmount : result.amount).formatWallet()}${result.currency ?? ''}",
                    // '${result.currency ?? ''} ${(result.amount ?? 0).keepDecimal()}',
                    style: TextStyle(
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w900,
                        color: Colors.white,
                        fontFamily: 'AR'),
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}
